package com.farm.command;


// 命令模式使用示例
public class CommandPatternDemo {
    public static void main(String[] args) {
        AgriculturalMachineReceiver seeder = new AgriculturalMachineReceiver("智能播种机#1");

        // 创建命令
        Command startCommand = new StartCommand(seeder);
        Command stopCommand = new StopCommand(seeder);
        Command speedCommand = new AdjustSpeedCommand(seeder, 5);

        // 创建调用者
        RemoteControlInvoker remote = new RemoteControlInvoker();

        // 执行启动命令
        remote.setCommand(startCommand);
        remote.pressButton();

        // 执行调速命令
        remote.setCommand(speedCommand);
        remote.pressButton();

        // 撤销调速命令
        remote.pressUndo();

        // 执行停止命令
        remote.setCommand(stopCommand);
        remote.pressButton();

        // 撤销停止命令
        remote.pressUndo();
    }
}
